package com.tanglongan.designPattern.dp10_proxy.demo99;

public class GenericClient {

    public static void main(String[] args) {
        Proxy proxy = new Proxy(new RealSubject());
        proxy.request();
    }

    /**
     * 抽象主题接口
     */
    interface ISubject {
        void request();
    }

    /**
     * 真实主题角色
     */
    static class RealSubject implements ISubject {
        @Override
        public void request() {
            System.out.println("real subject is called.");
        }
    }

    /**
     * 代理主题角色
     */
    static class Proxy implements ISubject {
        private final ISubject subject;

        public Proxy(ISubject subject) {
            this.subject = subject;
        }

        @Override
        public void request() {
            before();
            subject.request();
            after();
        }

        public void before() {
            System.out.println("============called before request()============");
        }

        public void after() {
            System.out.println("============called  after request()============");
        }
    }


}
